package com.project.controller;

import com.project.bean.SpeakBean;
import com.project.bean.UserBean;
import com.project.service.ISpeakService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("speak")
public class SpeakController {
    @Autowired
    private ISpeakService service;
    @RequestMapping("findBookById")
    public List<SpeakBean> findBookById(int id){
        return service.findByBook(id);
    }
    @RequestMapping("add")
    public String add(int bookId,String content, HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("logUser");
        SpeakBean speak = new SpeakBean(user.getId(),bookId,content);
        service.add(speak);
        return "ok";
    }
}
